#include "Protocol.hpp"
#include "Sock.hpp"

void Usage(string proc)
{
    cout << "Usage:" << proc << "ip port" << endl;
    exit(1);
}

int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        Usage(argv[0]);
        exit(1);
    }
    int sock = Sock::Socket();
    Sock::Connect(sock, argv[1], atoi(argv[2]));
    while (true)
    {
        request_t req;
        memset(&req, 0, sizeof(req));
        cout << "Please Enter Data One# ";
        cin >> req.x;
        cout << "Please Enter Data Two# ";
        cin >> req.y;
        cout << "Please Enter operator# ";
        cin >> req.op;
        write(sock, &req, sizeof(req));
        response_t resp;
        ssize_t s = read(sock, &resp, sizeof(resp));
        if (s == sizeof(resp))
        {
            cout << "code:" << resp.code << endl;
            cout << "result: " << resp.result << endl;
        }
        else
        {
            break;
        }
    }
    return 0;
}